home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #1 / Amiga Plus CD - 2000 - No. 1.iso / Tools / Text / Edit / GoldED-Demo / installdata / golded / developer / scanner / examples / includes / include.c
Encoding:
C/C++ Source or Header  |  1999-12-03  |  2.3 KB  |  108 lines

  1. /* -----------------------------------------------------------------------------
  2.  
  3.   Scan handler looking for include lines.
  4.  
  5.   Scan handlers are plain functions (loadSeg()'ed): no standard C startup
  6.   code and no library calls permitted. We have to put string constants into
  7.   the code segment (DICE compiler: option -ms1).
  8.  
  9.   DICE:
  10.  
  11.   dcc include.c -// -l0 -md -mRR -o golded:etc/scanner/include
  12.  
  13.   ------------------------------------------------------------------------------
  14. */
  15.  
  16. #include <exec/types.h>
  17.  
  18. ULONG
  19. ScanHandlerInclude(__D0 ULONG len, __A0 char **text, __A1 ULONG *line)
  20. {
  21.     const char *version = "$VER: Include 1.5 (" __COMMODORE_DATE__ ")";
  22.  
  23.     STRPTR textPtr = *text;
  24.  
  25.     // ignore leading spaces
  26.  
  27.     while (len && ((*textPtr == ' ') || (*textPtr == 9))) {
  28.  
  29.         ++textPtr;
  30.         --len;
  31.     }
  32.  
  33.     // is the next word #include ?
  34.  
  35.     if (len > 8) {
  36.  
  37.         if ((textPtr[0] == '#') && (textPtr[1] == 'i') && (textPtr[2] == 'n') && (textPtr[3] == 'c') && (textPtr[4] == 'l') && (textPtr[5] == 'u') && (textPtr[6] == 'd') && (textPtr[7] == 'e')) {
  38.  
  39.             textPtr += 8;
  40.             len     -= 8;
  41.  
  42.             // ignore spaces before argument
  43.  
  44.             while (len && ((*textPtr == ' ') || (*textPtr == 9))) {
  45.  
  46.                 ++textPtr;
  47.  
  48.                 --len;
  49.             }
  50.  
  51.             if (len) {
  52.  
  53.                 UWORD marker;
  54.  
  55.                 // determine argument delimiter
  56.  
  57.                 switch (*textPtr) {
  58.  
  59.                     case 34:
  60.  
  61.                         marker = 34;
  62.  
  63.                         ++textPtr;
  64.                         --len;
  65.  
  66.                         break;
  67.  
  68.                     case '<':
  69.  
  70.                         marker = '>';
  71.  
  72.                         ++textPtr;
  73.                         --len;
  74.  
  75.                         break;
  76.  
  77.                     default:
  78.  
  79.                         marker = FALSE;
  80.                 }
  81.  
  82.                 if (len && marker) {
  83.  
  84.                     UWORD letters = 0;
  85.  
  86.                     // result begins here (e.g. "file name" or <file name>)
  87.  
  88.                     *text = textPtr;
  89.  
  90.                     // determine agument length
  91.  
  92.                     while (--len) {
  93.  
  94.                         ++letters;
  95.                         ++textPtr;
  96.  
  97.                         if (*textPtr == marker)
  98.  
  99.                             return(letters);
  100.                     }
  101.                 }
  102.             }
  103.         }
  104.     }
  105.  
  106.     return(0);
  107. }
  108.